console.log("init contentScript.js");

// const titleArr = document.getElementsByClassName("title-content-title");
// for (let i = 0; i < titleArr.length; i++) {
//   console.log(titleArr[i].innerHTML);
// }

// function wx_request(url: string, callback: Function) {
//   const xhr = new XMLHttpRequest();
//   xhr.open("GET", url);
//   xhr.onreadystatechange = function () {
//     if (xhr.readyState === 4) {
//       callback(xhr.responseText);
//     }
//   };
//   xhr.send();
// }

// wx_request(
//   "https://www.baidu.com/sugrec?&prod=pc_his&from=pc_web&json=1&sid=60272_60839_60886_60875_60897&hisdata=%5B%7B%22time%22%3A1723339681%2C%22kw%22%3A%22%E7%BE%8E%E5%9B%BD%E8%B7%B3%E9%AB%98%E9%80%89%E6%89%8B%E6%8B%92%E7%BB%9D%E5%85%B1%E4%BA%AB%E9%87%91%E7%89%8C%20%E5%8A%A0%E8%B5%9B%E4%B8%A2%E9%87%91%22%7D%2C%7B%22time%22%3A1727446181%2C%22kw%22%3A%22%E5%AE%8B%E4%BD%B3%E6%99%92%E5%92%8C%E5%BC%A0%E6%A1%82%E6%A2%85%E5%90%88%E5%BD%B1%22%7D%2C%7B%22time%22%3A1727446215%2C%22kw%22%3A%22%E6%88%BF%E5%9C%B0%E4%BA%A7%E6%96%B0%E6%94%BF%E9%A6%96%E6%97%A5%3A%E6%88%BF%E4%B8%9C%E4%B8%8D%E6%84%BF%E5%86%8D%E8%AE%A9%E4%BB%B7%22%7D%2C%7B%22time%22%3A1728203703%2C%22kw%22%3A%22%E5%BC%80%E5%A7%8B%E5%90%AC%E5%8F%8D%E6%96%B9%E5%90%91%E7%9A%84%E9%92%9F%E4%BA%86%22%7D%2C%7B%22time%22%3A1728203757%2C%22kw%22%3A%22%E4%BF%9D%E5%AE%89%E5%A4%A7%E5%93%A5%E8%BF%98%E6%B2%A1%E6%84%8F%E8%AF%86%E5%88%B0%E4%BB%96%E9%A9%AC%E4%B8%8A%E6%88%90%E4%B8%BA%E6%99%AF%E7%82%B9%22%7D%2C%7B%22time%22%3A1728203881%2C%22kw%22%3A%22%E9%BE%99%E9%BE%96%E9%BE%98%E8%A9%9F%E6%80%8E%E4%B9%88%E8%AF%BB%22%7D%2C%7B%22time%22%3A1728204439%2C%22kw%22%3A%22%E6%AD%A6%E6%B1%89%E5%A4%A9%E6%B0%94%22%2C%22fq%22%3A5%7D%2C%7B%22time%22%3A1728204486%2C%22kw%22%3A%22%E6%96%B0%E4%BA%BA%E7%BB%93%E5%A9%9A%E7%94%A8%E5%95%86%E5%9C%BA%E6%91%87%E6%91%87%E8%BD%A6%E5%BD%93%E5%A9%9A%E8%BD%A6%22%7D%2C%7B%22time%22%3A1728295440%2C%22kw%22%3A%22%E6%97%A5%E5%8E%86%22%2C%22fq%22%3A4%7D%2C%7B%22time%22%3A1729002679%2C%22kw%22%3A%22%E7%BB%88%E4%BA%8E%E8%B5%A2%E4%BA%86!%E5%9B%BD%E8%B6%B32%E6%AF%941%E5%87%BB%E8%B4%A5%E5%8D%B0%E5%B0%BC%22%7D%5D&_t=1729415700406&req=2&csor=0",
//   (res: any) => {
//     console.log("data --- ", res);
//   }
// );

// 选择你要监听的按钮
const button = document.querySelector("#test");
if (button) {
  // 添加点击事件监听器
  button.addEventListener("click", () => {
    console.log("Button was clicked!");
    // 你可以在这里执行其他操作，例如发送消息给背景脚本
    chrome.runtime.sendMessage({ action: "buttonClicked" }, (response) => {
      if (chrome.runtime.lastError) {
        console.error(chrome.runtime.lastError);
      } else {
        console.log(response.message); // 接收来自背景脚本的响应
      }
    });
  });
} else {
  console.warn("Button not found!");
}
